<?php
defined('IN_ADMIN') or exit('No permission resources.');
include $this->admin_tpl('header','admin');
?>
<div class="main-div">
<link type="text/css" rel="stylesheet" href="<?php echo CSS_PATH; ?>product/edit_hongbao.css" />
<style>
div.main-div {border:1px solid #bbdde5; margin:5px auto 10px auto; padding:2px; font-size:12px; width:660px;}
div.main-div table {margin:auto; text-align:center;}
</style>
<form method="post" action="?m=ushop&c=sale&a=send_by&menuid=<?php echo $_GET['menuid'];?>" id="theForm0">
    <table width="100%">
        <tbody>
            <tr>
                <td class="label">按用户等级发放红包:</td>
                <td>
                    <select name="rank_id" name="user_type">
                        <option value="0">全部</option>
                        <?php
							foreach($member_class as $value) {
						?>
                        	<option value="1"><?php echo $value; ?></option>
                        <?php
							}
						?>
                    </select>&nbsp;&nbsp;&nbsp;
                    <input type="checkbox" value="1" name="validated_email">只给通过邮件验证的用户发放红包
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align:center">
                    <input type="submit" class="button" value="确定发送红包" name="dosubmit0" onclick="document.getElementById('theForm0').submit();">
                </td>
            </tr>
        </tbody>
    </table>
</form>
</div>
<div class="main-div">
<form method="post" action="?m=ushop&c=sale&a=send_by&menuid=<?php echo $_GET['menuid'];?>" name="theForm" id="theForm"> 
    <div class="list-div">
        <table cellspacing="1" cellpadding="3">
            <tbody>
                <tr>
                    <th>会员列表：</th>
                    <th>操作</th>
                    <th>给下列用户发放红包</th>
                </tr>
                <tr>
                    <td width="45%" align="center">
                        <select multiple="true" style="width:260px" size="15" id="f_catids" onchange="javascript:addusers()">
                            <?php
                            foreach($member as $value) {
                            ?>
                                <option value="<?php echo $value ?>"><?php echo $value; ?></option>
                            <?php
                            }
                            ?>
                        </select>
                    </td>
                    <td align="center">
                        <p style="margin-bottom:10px;">&nbsp;&nbsp;<input type="button" disabled="disabled" class="button" onclick="transact('update','f_catids','catids', '');" value="&gt;" id="adduser"></p>
                        <p>&nbsp;&nbsp;<input type="button" class="button" onclick="transact('delete','','catids','');" value="&lt;" id="deletebutton"></p>
                    </td>
                    <td width="45%" align="center">
                        <select style="width:260px" size="15" multiple="true" id="catids" name="user[]"></select>
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right;" colspan="3"><input type="submit" class="button" value="确定发送红包" name="dosubmit" id="dosubmit" style="display:none;"></td>
                </tr>
            </tbody>
        </table>
    </div>
</form>
</div>
<script>
function addusers() {
	document.getElementById('adduser').disabled = false;
}
$("#dosubmit").click(function() {
	var len = $("#catids option").size();
	if(len<1) {
		alert('至少要添加一个会员');
		return false;
	}
	return true;
})

function transact(update,fromfiled,tofiled, num) {
	if(update=='delete') {
		var fieldvalue = $('#'+tofiled).val();
		$("#"+tofiled+" option").each(function() {
		   if($(this).val() == fieldvalue){
			$(this).remove();
		   }
		});
	} else {
		var fieldvalue = $('#'+fromfiled).val();
		var have_exists = 0;
		$("#"+tofiled+" option").each(function() {
		   if($(this).val() == fieldvalue){
			have_exists = 1;
			alert('已经添加到列表中');
			return false;
		   }
		});
		if(have_exists==0) {
			obj = $('#'+fromfiled+' option:selected');
			text = obj.text();
			text = text.replace('│', '');
			text = text.replace('├ ', '');
			text = text.replace('└ ', '');
			fieldvalue = "<option value='"+fieldvalue+"' selected='selected'>"+text+"</option>"
			$('#'+tofiled).append(fieldvalue);
			$('#deletebutton').attr('disabled','');
		}
	}
}

</script>
</body>
</html>